<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>项目列表</title>
    <?php PrintPageHead(); ?>
    <link href="../resource/css/hermes.css" rel="stylesheet">
    <link href="../resource/js/calendar/calendar-blue.css" type="text/css" rel="stylesheet">
    <script src="../resource/js/calendar/calendar.js" type="text/javascript"></script>
    <script src="../resource/js/hermes.js"></script>
    <style type="text/css">
       .form_d{
           width:500px;
           margin: 20px auto;
       }
    </style>
    <?php
    if (!array_key_exists("公众号ID",$_SESSION)) {
        header("Location:back.php");
    }
    if(isset($_REQUEST['id'])){
        $do= new Do推广文章();
        $内容=pdo()->selectBO($do,array('id'=>$_REQUEST['id']));
    }

    ?>
</head>
<body>

<!-- 配置文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../ueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        toolbars: [
            [ 'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|','link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'simpleupload', 'insertimage', 'emotion', 'scrawl', 'attachment', 'map', 'gmap', 'insertframe']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });
</script>

<div class="container-fluid">
    <?php include_once 'back_header.php'; ?>
    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title"><?php if($内容->data['标题'])echo "编辑";else echo "添加";?>用户推广文章</h3></div>

        <form action="" method="post">

            <div class="form_d"><span>标题:</span><input type="text" name="title" style="width: 250px" value="<?=@$内容->data['标题']?>"></div>
            <div class="form_d"><span>备注:</span><input type="text" name="备注" style="width: 250px" value="<?=@$内容->data['备注']?>"><span style="color: red">*显示给推广员</span></div>
            <div class="form_d"><span>内容:</span><!-- 加载编辑器的容器 -->
                <script id="container" name="content" type="text/plain"><?=@$内容->data['内容']?></script>
            </div>
            <div class="form_d"><input type="submit" name="okn" value="提交">  </div>

        </form>


    </div>





</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>

</body>
</html>
<?php
if(isset($_POST['okn'])){

    if($_REQUEST['title']==''||$_REQUEST['content']==''){
        echo "<script>alert('请认真填写信息');</script>";
    }else{
        if(isset($_REQUEST['id'])){
            $dos= new Do推广文章();
            $dos->set_id($_REQUEST['id']);
            $dos->set_标题($_REQUEST['title']);
            $dos->set_备注($_REQUEST['备注']);
            $dos->set_内容($_REQUEST['content']);
            $dos->set_公众号ID(G_SERV_ID);
            $dos->set_公众号openID($_SESSION['公众号openID']);
            $re= $dos->update();
            if($re){
                echo "<script>alert('修改成功');location.replace(location.href);</script>";
            }else{
                echo "<script>alert('修改失败或没有修改任何信息');</script>";
            }
        }else{
            $dos= new Do推广文章();
            $dos->set_标题($_REQUEST['title']);
            $dos->set_备注($_REQUEST['备注']);
            $dos->set_内容($_REQUEST['content']);
            $dos->set_公众号ID(G_SERV_ID);
            $dos->set_公众号openID($_SESSION['公众号openID']);
            $re= $dos->insert();
            if($re){
                echo "<script>alert('添加成功');</script>";
            }else{
                echo "<script>alert('添加失败');</script>";
            }
        }

    }

}
?>
